﻿using UnityEngine;
using System.Collections;
using strange.extensions.mediation.impl;
using strange.extensions.context.api;
using strange.extensions.dispatcher.eventdispatcher.api;
using System;

namespace CommonIoC
{
    public enum PlayerStageEvent
    {
        onChange,
        canMove,
        doTalk
    }


    public enum PlayerStage
    {

        canMove,
        doTalk
    }


    public enum MainUIEvent
    {
        CloseAllUI
    }


    public class PlayerStageManagerMediator :  Mediator
    {
        [Inject]
        public PlayerStageManagerView view { get; set; }

        [Inject(ContextKeys.CONTEXT_DISPATCHER)]//全局的dispatcher
        public IEventDispatcher dispatcher { get; set; }

        /// <summary>
        /// 这里做初始化的操作，相当于start
        /// </summary>
        public override void OnRegister()
        {
            //view.buttonClicked.AddListener(doManagement.Dispatch);
            view.gamestate = PlayerGameState.CanMove_And_CanTouchWSAD;

            //注册监听，，view分发的事件，，
          
            view.dispatcher.AddListener(PlayerGameState.IsTriggerEnterEnemy, onTriggerEnterEnemy);
            //  dispatcher.AddListener(FlowchartEvent.CHECK_TO_Talk, OnCheck_To_Talk);

         
           // dispatcher.AddListener( MainUIEvent.CloseAllUI, OnCloseAllUI);

            dispatcher.AddListener(PlayerGameState.IsDoingTalk, onIsDoingTalk);

            dispatcher.AddListener(PlayerGameState.CanMove_And_CanTouchWSAD, onCanMove_And_CanTouchWSAD);

        }

        private void onTriggerEnterEnemy(IEvent payload)
        {
            Debug.Log("onTriggerEnterEnemy");
            view.gamestate = PlayerGameState.IsTriggerEnterEnemy;
            dispatcher.Dispatch(PlayerGameState.IsDoingTalk);
          
          
        }

        private void onCanMove_And_CanTouchWSAD(IEvent payload)
        {
            view.gamestate = PlayerGameState.CanMove_And_CanTouchWSAD;
            view.ChangeStageTocanMove();
         
          
        }

        private void onIsDoingTalk(IEvent payload)
        {
            view.gamestate = PlayerGameState.IsDoingTalk;
          
        }

      
     
    }
}
